<?php
class applicationComponents extends sfComponents{

  public function executeSkins()
  {
  	
    
  	
  }
  
  public function executeFlash()
  {
  	$palcoPrincipalFlash = new FlashObject("http://www.palcoprincipal.com/widget/playerUsers/user/derbouka/estilo/1");
  	$palcoPrincipalFlash->addParam('id',"mp3player");
  	$palcoPrincipalFlash->addParam('width',"200.3");
  	$palcoPrincipalFlash->addParam('height',"196.9");
  	$palcoPrincipalFlash->addParam('align',"center");
  	$palcoPrincipalFlash->addParam('allowscriptaccess',"sameDomain");
  	$palcoPrincipalFlash->addParam('wmode',"transparent");
  	$palcoPrincipalFlash->addParam('quality',"high");
  	
  	$this->loadFlashFunction = new JSFunction('loadFlash');
  	$flashLoad_variable = new JSVariable('flash_div',"'flash_load_div'");
  	$this->loadFlashFunction->addVariable($flashLoad_variable);
  	
  	$this->loadFlashFunction->setContent(GadgetsFlash::embedFlash($flashLoad_variable,$palcoPrincipalFlash));
  	echo JSFunction::addJSTags($this->loadFlashFunction);
  }
  
  public function executeGadgetsMakeRequest()
  {
  	$feed_request = new FeedGadgetRequest('feedRequest','http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml');
    $text_request = new TextGadgetRequest('textRequest','http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml');
  	$dom_request = new DomGadgetRequest('domRequest','http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml');
  	$json_request = new JsonGadgetRequest('jsonRequest','http://graargh.returnstrue.com/buh/fetchme.php');
  	$post_request = new GadgetRequest('postRequest','http://graargh.returnstrue.com/buh/fetchme.php');
  	$post_request->setPostData(GadgetsIO::encodeValues('{ data1 : "test", data2 : 1234566 }',true));
  	$post_request->setMethod(GadgetMethodType::POST);
  	
    $this->feed_response = GadgetsIO::makeRequest($feed_request);
    $this->text_response = GadgetsIO::makeRequest($text_request);
    $this->dom_response = GadgetsIO::makeRequest($dom_request);
    $this->json_response = GadgetsIO::makeRequest($json_request);
    $this->post_response = GadgetsIO::makeRequest($post_request);
  }
  public function executeGadgetsPrefs()
  {
  	$this->gadget = new GadgetsPrefs('gadget');
  }
  
  public function executeDataRequest()
  {
    $this->viewer_friends = new OSViewerFriends('viewer_friends');
    
    $this->people_request = new OSPeopleRequest($this->viewer_friends);
    $this->people_request->addProfileDetails(OSPersonField::PROFILE_URL);
    
    $data_request = new OSDataRequest('requestInfo');
    $data_request->addRequest($this->people_request);
    
    $this->data_response = $data_request->send(true);
    echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler($data_request->getDataRequestFunction()));
  }
  
  public function executePersonRequest()
  {
    $this->viewer = new OSViewer('viewer');
    $this->owner = new OSOwner('owner');
    
    $this->viewer_request = new OSPersonRequest($this->viewer);
    $this->viewer_request->addProfileDetails(OSPersonField::PROFILE_URL);
    
    $this->owner_request = new OSPersonRequest($this->owner);
    $this->owner_request->addProfileDetails(OSPersonField::PROFILE_URL);
    
    $data_request = new OSDataRequest('requestPerson');
    $data_request->addRequest($this->viewer_request);
    $data_request->addRequest($this->owner_request);
    
    $this->data_response = $data_request->send(true);
    echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler($data_request->getDataRequestFunction()));
  }
  
  public function executeUpdateAppDataRequest()
  {
    
    $this->viewer = new OSViewer('viewer');
    
    $this->viewer_request = new OSPersonRequest($this->viewer);
    $this->viewer_request->addProfileDetails(OSPersonField::PROFILE_URL);
    
    $this->app_data1 = new OSPersonAppData($this->viewer,"AppData1",'Math.random() * 5');
    $this->app_data2 = new OSPersonAppData($this->viewer,"AppData2",'Math.random() * 100');
    $this->app_data3 = new OSPersonAppData($this->viewer,"AppData3",'new Date().getTime()');

    // cria o objecto para fazer update dos AppData
    $this->updateViewerData_request = new OSUpdatePersonAppDataRequest();
    $this->updateViewerData_request->addPersonAppData($this->app_data1);
    $this->updateViewerData_request->addPersonAppData($this->app_data2);
    $this->updateViewerData_request->addPersonAppData($this->app_data3);
    
    $this->appDatarequest = new OSDataRequest('requestAppData');
    $this->appDatarequest->addRequest($this->updateViewerData_request);
    
    // cria o objecto para fazer o "fectch" dos AppData
    $this->fetchViewerData_request = new OSFetchPersonAppDataRequest($this->viewer);
    $this->fetchViewerData_request->fetchPersonAppData($this->app_data1);
    $this->fetchViewerData_request->fetchPersonAppData($this->app_data2);
    $this->fetchViewerData_request->fetchPersonAppData($this->app_data3);
    
    
    $data_request = new OSDataRequest('requestInfo');
    $data_request->addRequest($this->viewer_request);
    $data_request->addRequest($this->fetchViewerData_request);
    
    // faz com que o OSDataRequest fiquem ligados.
    $this->appDatarequest->appendDataRequest($data_request);
    
    $this->appDatarequest->send(true);
    
    $this->data_response = $data_request->send(true);
    echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler($data_request->getDataRequestFunction()));
  
  }

  public function executeFetchActivityRequest()
  {
  	$viewer = new OSViewer('viewer');
  	$viewer_friends = new OSViewerFriends('viewer_friends');
  	
  	
  	$this->viewerActivities = new OSFetchActivitiesRequest($viewer);
  	$this->friendActivities = new OSFetchActivitiesRequest($viewer_friends);
  	$this->data_request = new OSDataRequest('requestInfo');
    $this->data_request->addRequest($this->viewerActivities);
    $this->data_request->addRequest($this->friendActivities);
    
    $this->data_response = $this->data_request->send(true);
    echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler($this->data_request->getDataRequestFunction()));
  }
  
  public function executeOpensocial_lib(){

  }
  public function executeEnvironment(){
    $this->env = new OSEnvironment('env');
  }
 
  public function executeViews()
  {
  }
  public function executeMinimessage()
  {
  	$dismissibleMessage = new GadgetsMiniMessage('dismissibleMessage');
  	$staticMessage = new GadgetsMiniMessage('staticMessage');
  	$timerMessage = new GadgetsMiniMessage('timerMessage');
  	
  	$this->dismissibleMessageFunction = new JSFunction('dismissibleMessageFunction');
  	$this->staticMessageFunction = new JSFunction('staticMessageFunction');
  	$this->timerMessageFunction = new JSFunction('timerMessageFunction');
  	$this->dismissStaticMessageFunction = new JSFunction('dismissStaticMessageFunction');
  	
  	$content = $dismissibleMessage->initialize();
  	$content .= $dismissibleMessage->createDismissibleMessage('<div>You can dismiss this message!</div>');
    $this->dismissibleMessageFunction->setContent($content);
    echo JSFunction::addJSTags($this->dismissibleMessageFunction);
  	
  	$content = $staticMessage->initialize();
  	$content .= $staticMessage->createStaticMessage('This is a static message!','div_static');
    $this->staticMessageFunction->setContent($content);
    echo JSFunction::addJSTags($this->staticMessageFunction);
  	
  	$content = $timerMessage->initialize();
  	$content .= $timerMessage->createTimerMessage('<div>This message will remove it self in 5 secounds!</div>',5);
    $this->timerMessageFunction->setContent($content);
    echo JSFunction::addJSTags($this->timerMessageFunction);
  	
  	$content = $staticMessage->initialize();
  	$content .= $staticMessage->dismissMessage('div_static');
    $this->dismissStaticMessageFunction->setContent($content);
    echo JSFunction::addJSTags($this->dismissStaticMessageFunction);

  }
  
  public function executeActivity(){
    $this->activity = new OSActivity('update_musics');

    $this->mediaItem = new OSActivityMediaItem('logo');
    $this->mediaItem->setImageItem();
    $this->mediaItem->setURL('http://www.palcoprincipal.com/images/logo_opensocial_pp.png');

    $this->activity->addMediaItem($this->mediaItem);
    $this->activity->setPattern('title','O utilizador %s actualizou a musica %s às %s!');
  }
  
  public function executeTabs2()
  {
    $this->tabset = new GadgetsTabSet('tabset','tabs_div');
  }
  
  public function executeTabs()
  {
    //the JavaScript update function
    $this->updateFunction = new JSFunction('update');
    //the JavaScript function that will be called when this gadget starts
    $this->onLoadHandler = new JSFunction('onLoadHandler');   
    
    // the TabSet
    $this->tabset = new GadgetsTabSet('tabset','tabs_div');
    
    // sample tabs 
    $this->tab1 = new GadgetsTab("tab1");
    $this->tab1->setCallback($this->updateFunction);
    
    $this->tab2 = new GadgetsTab("tab2");
    $this->tab2->setCallback($this->updateFunction);
    
    
    // this will initialize the tabset variable
    $this->onLoadHandler->addContent($this->tabset->getVarName().' = '.$this->tabset->initialize(false));
    
    // here w're going to add tabs to this tabset
    $this->onLoadHandler->addContent($this->tabset->addTab($this->tab1));
    $this->onLoadHandler->addContent($this->tabset->addTab($this->tab2));
    
    // this will call the javascript function loadTabsCombobox() defined in the view
    $this->onLoadHandler->addContent("loadTabsCombobox();");
    
    
    // align Javascript Function
    $this->align = new JSFunction('align','align',$this->tabset->alignTabs('align'));
    
    // display tabs javascript function
    $this->displayTabs = new JSFunction('displayTabs','display',$this->tabset->displayTabs('display'));
    //echo $this->tabset->displayTabs();

    
    echo JSFunction::addJSOpenTag();
    
    // this will make the tabset global
    echo $this->tabset->initializeVariable();
    // this will load the onLoadHandler function when the gadget loads
    echo GadgetsUtil::registerOnLoadHandler($this->onLoadHandler);
    echo JSFunction::renderFunction($this->onLoadHandler);
    
    // add align javascript function
    echo $this->align;
    echo $this->displayTabs;
    
    
    echo JSFunction::addJSCloseTag();
    
    
  }

  public function executeNotification(){

  }
   
  /*public function executeListPersonFriends(){
    $oSRequest = new OSRequest('req','opt_params','listViewerFriends',null);
    $this->oSContainer = new OSContainer($this->oSGadget,$oSRequest,'listViewerFriends_response','data');
    $this->friend = new OSFriend('friend');
    $this->viewer_friends = new OSViewerFriends($this->oSContainer,$this->friend,'viewer_friends');
    $this->oSContainer->getOSRequest()->fecthFriends($this->viewer_friends);
    echo $this->oSContainer->getOSRequest()->execute($this->oSContainer);
  }

  
  public function executeViewOwner(){
    $this->oSContainer = new OSContainer($this->oSGadget,new OSRequest('req','opt_params','viewOwner',null),'viewOwner_response','data');
    $this->owner = new OSOwner($this->oSContainer,'owner');
    $this->oSContainer->getOSRequest()->fecthUser($this->owner);
    echo $this->oSContainer->getOSRequest()->execute($this->oSContainer);
  }
  public function executeViewViewer(){    
    $oSRequest = new OSRequest('req','opt_params','viewViewer',null);
    $this->oSContainer = new OSContainer($this->oSGadget,$oSRequest,'viewViewer_response','data');
    $this->viewer = new OSViewer($this->oSContainer,'viewer');
    $this->oSContainer->getOSRequest()->fecthUser($this->viewer);
    echo $this->oSContainer->getOSRequest()->execute($this->oSContainer);
  }

  public function executeViewViewerAndOwner(){

    $oSRequest = new OSRequest('req','opt_params','viewViewer',null);
    $this->oSContainer = new OSContainer($this->oSGadget,$oSRequest,'viewViewer_response','data');
    $this->viewer = new OSViewer($this->oSContainer,'viewer');
    $this->oSContainer->getOSRequest()->fecthUser($this->viewer);
    echo $this->oSContainer->getOSRequest()->execute($this->oSContainer);

  
    $this->oSContainer2 = new OSContainer($this->oSGadget,new OSRequest('req','opt_params','viewOwner',null),'viewOwner_response','data');
    $this->owner = new OSOwner($this->oSContainer2,'owner');
    $this->oSContainer2->getOSRequest()->fecthUser($this->viewer);
    echo $this->oSContainer2->getOSRequest()->execute($this->oSContainer2);
  }

  public function executeViewPerson(){
    $this->update_div = ($this->update_div)? $this->update_div : 'viewPerson_div'; 
    $this->request_func = ($this->request_func)? $this->request_func : 'viewPerson'; 
    $this->response_func = ($this->response_func)? $this->response_func : ($this->request_func.'_response'); 
    $this->person_type = ($this->person_type)? $this->person_type : 'VIEWER'; 
    $this->person_type_var = ($this->person_type_var)? $this->person_type_var : 'person'; 
  }*/
}

